﻿using BW.EatRabbit.API.Application.Commands;
using BW.EatRabbit.Domain;
using BW.EatRabbit.ErrorCode;
using BW.EatRabbit.Infrastructure.Interfaces;
using MediatR;
using System.Diagnostics.Eventing.Reader;

namespace BW.EatRabbit.API.Application.CommandHandlers
{
    public class GoodsQueryCommandHandler : IRequestHandler<GoodsQueryCommand,APIResult<List<Goods>>>
    {
        private readonly IBaseRepository<Goods> goodsRepository;
        public GoodsQueryCommandHandler(IBaseRepository<Goods> goodsRepository)
        {

            this.goodsRepository = goodsRepository;
        }
        public Task<APIResult<List<Goods>>> Handle(GoodsQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Goods>> result = new APIResult<List<Goods>>();
            result.Code = ResultCode.查询成功;
            result.Message = ResultCode.查询成功.ToString();

            var list = goodsRepository.GetAll();
            result.Data = list.ToList();
            //var csredis = new CSRedis.CSRedisClient("127.0.0.1:6379,defaultDatabase=1,prefix=my_");

            //var code = csredis.Get("name");

            //var str = goodsRepository.GetAll().ToList();

            //if (code == null)
            //{

            //    csredis.Set("name", str[2].GoodsName);
            //    result.Code = ResultCode.查询成功;
            //    result.Message = "查询成功";

            //    result.Data = str;
            //}
            //else
            //{
            //    result.Code = ResultCode.查询成功;
            //    result.Message = "查询成功";
            //    result.Data = str;
            //    csredis.Del("name");
            //}









            return Task.FromResult(result);
        }
    }
}
